﻿using AutoMapper;
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Mvc;
using MiniErp.Core.Filters;
using MiniErp.Entity.DataStreams.BOs;
using MiniErp.Entity.DataStreams.DTOs.AssetManagement;
using MiniErp.Service.JWTService.IService;
using MiniErp.Service.MysqlService.IService;
using MiniErp.Service.MysqlService.IService.IAssetManagement;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Security.Claims;
using System.Threading.Tasks;


namespace MiniErp.Core.Controllers.AssetManagement
{
    /// <summary>
    /// 资产管理系统主页控制层
    /// </summary>
    [Route("AssetManagementIndex")]
    public class AssetIndexController : ApiControllers
    {
        private readonly IAssetIndexService _assetIndexService;
        public AssetIndexController(IAssetIndexService assetIndexService)
        {
            _assetIndexService = assetIndexService;
        }

        /// <summary>
        /// 增加一条资产信息
        /// </summary>
        /// <param name="addassetInfoDTO">要增加的资产信息dto</param>
        /// <returns></returns>
        [Authorize(Policy = "Admin")]
        [HttpPost]
        [Route("AddAssetInfo")]
        public async Task<bool> AddAssetInfo(AddAssetInfoDTO addassetInfoDTO)
        {
            return await _assetIndexService.AddAssetInfoAsync(addassetInfoDTO);
        }

        /// <summary>
        /// 修改一条资产信息
        /// </summary>
        /// <param name="updateAssetInfoDTO">要修改的资产信息dto</param>
        /// <returns></returns>
        [Authorize(Policy = "Admin")]
        [HttpPost]
        [Route("UpdatessetInfo")]
        public async Task<bool> UpdatessetInfo(UpdateAssetInfoDTO updateAssetInfoDTO)
        {
             return await _assetIndexService.UpdateAssetInfoAsync(updateAssetInfoDTO);
        }

        /// <summary>
        /// 查询所有资产信息(分页)
        /// </summary>
        /// <param name="pageBO">分页实体</param>
        /// <returns></returns>
        [Authorize(Policy = "Root")]
        [HttpPost]
        [Route("GetAllAssetInfo")]
        public async Task<List<AssetInfoDTO>> GetAllAssetInfoAsync(PageBO pageBO)
        {
            return await _assetIndexService.GetAllAssetInfoAsync(pageBO);
        }

        /// <summary>
        /// 模糊查询所有资产信息(分页)
        /// </summary>
        /// <param name="value">模糊查询值</param>
        /// <param name="pageBO">分页实体</param>
        /// <returns></returns>
        [Authorize(Policy = "Root")]
        [HttpPost]
        [Route("GetFuzzyAssetInfo")]
        public async Task<List<AssetInfoDTO>> GetFuzzyAssetInfoAsync(string value, PageBO pageBO)
        {
            return await _assetIndexService.GetFuzzyAssetInfoAsync(value, pageBO);
        }

        /// <summary>
        /// 删除指定编号的资产信息
        /// </summary>
        /// <param name="gid">资产总类型编号</param>
        /// <param name="sid">资产次级类型编号</param>
        /// <param name="aid">资产编号</param>
        /// <returns></returns>
        [Authorize(Policy = "Root")]
        [HttpPost]
        [Route("DeleteAssetInfoAsync")]
        public async Task<bool> DeleteAssetInfoAsync(int gid, int sid, int aid)
        {
            return await _assetIndexService.DeleteAssetInfoAsync(gid, sid, aid);
        }

    }
}
